package com.cgbl.cg.view

import android.content.Context
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.cg.R
import com.cgbl.cg.adapter.FilterAdapter
import com.lxj.xpopup.impl.PartShadowPopupView
import com.robot.base.model.CourseAllTypeBean

class ProjectFilterPop(
    context: Context,
    val select: String,
    val list: MutableList<CourseAllTypeBean>
) :
    PartShadowPopupView(context) {
    private var confirmClickListener: (id: CourseAllTypeBean) -> Unit = {}
    private lateinit var recyclerView: RecyclerView
    private lateinit var selectCourseAdapter: FilterAdapter
    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_project_filter
    }

    override fun initPopupContent() {
        super.initPopupContent()

        recyclerView = findViewById(R.id.recyclerView)
        selectCourseAdapter = FilterAdapter(select)
        recyclerView.adapter = selectCourseAdapter
        selectCourseAdapter.setOnItemClickListener { adapter, view, position ->
            confirmClickListener.invoke(list[position])
        }

        selectCourseAdapter.setNewInstance(list.mapNotNull { it.name }.toMutableList())
    }


    fun setConfirmClickListener(click: (id: CourseAllTypeBean) -> Unit): ProjectFilterPop {
        confirmClickListener = click
        return this
    }
}